package com.xdxc.response;

import lombok.Data;

@Data
public class ApiResponse<T> {
    private int code; // 状态码
    private String msg; // 提示信息
    private T data; // 数据

    // 成功响应
    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode(200); // 默认成功状态码
        response.setMsg("Success");
        response.setData(data);
        return response;
    }

    // 错误响应
    public static <T> ApiResponse<T> error(int code, String msg) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode(code);
        response.setMsg(msg);
        response.setData(null);
        return response;
    }
}